package com.scm.servlet.pomain;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.page.Page;
import com.scm.model.Pomain;
import com.scm.service.PomainService;

/**
 * Servlet implementation class ListNewPomainServlet
 */
@WebServlet("/main/pomain/ListNewPomain")
public class ListNewPomainServlet extends HttpServlet {
	private static final long serialVersionUID = -3141680600230174019L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String currentpagestr = req.getParameter("currentPage");
		int currentPage = 1;
		if(currentpagestr != null && currentpagestr.matches("\\d++")) {
			currentPage = Integer.parseInt(currentpagestr);
		}
		String poId = req.getParameter("poId");
			if("null".equals(poId)) {
				poId=null;
			}
		String venderName = req.getParameter("venderName");
		String payType = req.getParameter("payType");
			if("货到付款".equals(payType)) {
				payType="1";
			}else if("款到发货".equals(payType)) {
				payType="2";
			}else if("预付款到发货".equals(payType)) {
				payType="3";
			}
		String startDate = req.getParameter("startDate");
		String endDate = req.getParameter("endDate");
		Map<String,String> querymap = new HashMap<String,String>();
		querymap.put("status", "1");
		querymap.put("poId",poId);
		querymap.put("venderName",venderName);
		querymap.put("payType",payType);
		querymap.put("startDate",startDate);
		querymap.put("endDate",endDate);
		try {
			Page<Pomain> page = new PomainService().selectPage(currentPage, querymap);
			req.setAttribute("page", page);
			req.getRequestDispatcher("/gztm/newpomain_detail.jsp").forward(req, resp);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
